<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>例子25-JS进阶（二）</title>
    </head>

    <body class="cols">
        <pre>
            <code>
                    // 例子25

                    var Tom = {
                        name: 'Tom',
                        age: 20,
                        getName: function() {
                            return this.name
                        }
                    };

                    var Jerry = {
                        name: 'Jerry',
                        age: 22,
                        getName: function() {
                            return this.name
                        }
                    }
            </code>
        </pre>
        <pre>
            <code>
                    var person = function(name, age) {

                        // 声明一个中间对象，该对象就是工厂模式的模子
                        var o = new Object();

                        // 依次添加我们需要的属性与方法
                        o.name = name;
                        o.age = age;
                        o.getName = function() {
                            return this.name;
                        }

                        return o;
                    }

                    // 创建两个实例
                    var Tom = person('Tom', 20);
                    var Jerry = person('Jerry', 22);
            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/25.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>

</html>